﻿@model ShipmentDetailsModel

@using SmartStore.Web.Models.Common;
@using SmartStore.Web.Models.Order;

@{
	Layout = "_Layout";

	Html.AddTitleParts(T("PageTitle.ShipmentDetails").Text);
}

<div class="page shipment-details">
    <div class="page-title">
        <h1 class="h2">
			@T("Order.Shipments.Information", Model.Id)
		</h1>
    </div>

    <div class="page-body">
		<div class="card card-body shipment-box mb-4">
			<div class="row">
				<div class="col-6 col-md-4">
					<h5>@T("Order.Shipments.Order#")</h5>
					<p>
						<a href='@Url.Action("Details", "Order", new { id = Model.Order.Id })'>@Model.Order.Id</a>
					</p>

					<h5>@T("Order.Shipments.ShippedDate")</h5>
					<p>
						@if (Model.ShippedDate.HasValue)
						{
							@Model.ShippedDate.Value.ToNativeString("D")
						}
						else
						{
							<span class="text-muted">@T("Order.Shipments.ShippedDate.NotYet")</span>
						}
					</p>

					<h5>@T("Order.Shipments.DeliveryDate")</h5>
					<p>
						@if (Model.DeliveryDate.HasValue)
						{
							@Model.DeliveryDate.Value.ToNativeString("D")
						}
						else
						{
							<span class="text-muted">@T("Order.Shipments.DeliveryDate.NotYet")</span>
						}
					</p>
				</div>
				<div class="col-6 col-md-4">
					<h5>@T("Order.Shipments.ShippingMethod")</h5>
					<p>@Model.Order.ShippingMethod</p>

					@if (Model.TrackingNumber.HasValue())
					{
						<h5>@T("Order.Shipments.TrackingNumber")</h5>
						<p>
							@if (Model.TrackingNumberUrl.HasValue())
							{
								<a href="@Model.TrackingNumberUrl" target="_blank" class="tracking-url" rel="nofollow">@Model.TrackingNumber</a>
							}
							else
							{
								@Model.TrackingNumber
							}
						</p>
					}
				</div>
				<div class="col-12 col-md-4">
					<h5>@T("Order.Shipments.ShippingAddress")</h5>
					@RenderAddress(Model.Order.ShippingAddress)
				</div>
			</div>
		</div>

        @if (Model.Items.Count > 0)
        {
            <fieldset class="content-group">
				<h4 class="mb-3">@T("Order.Shipments.Product(s)")</h4>

                <div class="products-box table-responsive">
                    <table class="table table-hover">
						<colgroup>
							@if (Model.ShowSku)
							{
								<col width="1" />
							}
							<col />
							<col />
						</colgroup>
                        <thead>
                            <tr>
                                @if (Model.ShowSku)
                                {
                                    <th>@T("Order.Shipments.Product(s).SKU")</th>
                                }
                                <th>@T("Order.Shipments.Product(s).Name")</th>
                                <th class="text-center">@T("Order.Shipments.Product(s).Quantity")</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach (var item in Model.Items)
                            {
                                <tr>
                                    @if (Model.ShowSku)
                                    {
                                        <td>@item.Sku</td>
                                    }
                                    <td>
                                        <div><a href="@item.ProductUrl" title="@T("Products.Details")" @Html.LanguageAttributes(item.ProductName)>@item.ProductName</a></div>
                                        @if (item.AttributeInfo.HasValue())
                                        {
                                            <div class="attributes text-muted mt-1">
                                                @Html.Raw(item.AttributeInfo)
                                            </div>
                                        }
                                    </td>
                                    <td class="text-center">
                                        @item.QuantityShipped
                                    </td>
                                </tr>
                            }
                        </tbody>
                    </table>
                </div>
            </fieldset>
        }

        @if (Model.ShipmentStatusEvents.Count > 0)
        {
            <div class="shipment-status-events">
				<h4 class="mb-3">@T("Order.ShipmentStatusEvents")</h4>

                <div class="shipment-status-events-box table-responsive">
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th>@T("Order.ShipmentStatusEvents.Event")</th>
                                <th>@T("Order.ShipmentStatusEvents.Location")</th>
                                <th>@T("Order.ShipmentStatusEvents.Country")</th>
                                <th>@T("Common.Date")</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach (var item in Model.ShipmentStatusEvents)
                            {
                                <tr>
                                    <td>@item.EventName</td>
                                    <td>@item.Location</td>
                                    <td>@item.Country</td>
                                    <td>
                                        @if (item.Date.HasValue)
                                        {
                                            @item.Date.Value.ToNativeString("D")
                                        }
                                    </td>
                                </tr>
                            }
                        </tbody>
                    </table>
                </div>
            </div>
        }
    </div>
</div>


@helper RenderAddress(AddressModel address)
{
	var cityStateZip = address.GetFormattedCityStateZip();

	<div class="mb-2">
		@Html.Raw(address.FormattedAddress)
	</div>

	<div class="email">
		<span class="pr-1">@T("Order.Email"):</span>
		<span>@address.Email</span>
	</div>
	if (address.PhoneEnabled && address.PhoneNumber.HasValue())
	{
		<div class="phone">
			<span class="pr-1">@T("Order.Phone"):</span>
			<span>@address.PhoneNumber</span>
		</div>
	}
	if (address.FaxEnabled && address.FaxNumber.HasValue())
	{
		<div class="fax">
			<span class="pr-1">@T("Order.Fax"):</span>
			<span>@address.FaxNumber</span>
		</div>
	}
}
